<template>
  <el-card class="box-card">
    <el-table :data="tableData" style="width: 100%">
      <el-table-column fixed prop="createTime" label="日期" width="200" />
      <el-table-column prop="productId" label="商品ID" width="150" />
      <el-table-column prop="productImage" label="商品图片" width="150">
        <template slot-scope="scope">
          <img :src="scope.row.productImage" width="50" height="50">
        </template>
      </el-table-column>
      <el-table-column prop="productName" label="商品名称" width="150" />
      <el-table-column prop="isDirect" label="是否直营" width="100" />
      <el-table-column prop="productNum" label="库存" width="100" />
      <el-table-column prop="salePrice" label="商品价格" width="150" />
      <el-table-column fixed="right" label="操作" width="150">
        <template slot-scope="scope">
          <el-button
            type="text"
            size="small"
            @click.native.prevent="deleteRow(scope.$index, tableData)"
          >
            移除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-card>
</template>

<script>
import { goodsList, delGoods } from '../../api/user'
export default {
  filters: {
    isHaveData(oldVue) {
      return oldVue === true ? '直营' : '非直营'
    }
  },
  data() {
    return {
      tableData: []
    }
  },
  mounted() {
    goodsList().then((res) => {
      const list = res.data.list
      this.tableData = list
      console.log(this.tableData)
    })
  },
  methods: {
    deleteRow(index, rows) {
      console.log(index, rows)
      const data = {
        productId: rows[index].productId
      }
      console.log(data)
      delGoods(data).then((res) => {
        rows.splice(index, 1)
      })
    },
    formDate(time) {
      var d = new Date(time)
      var h = d.getHours()
      var m = d.getMinutes()
      if (h < 10) {
        h = '0' + h
      }
      if (m < 10) {
        m = '0' + m
      }
      console.log(h + ':' + m)
      return h + ':' + m
    }
  }
}
</script>

<style>
  .text {
    font-size: 14px;
  }

  .item {
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both
  }

  .box-card {
    margin: 20px;
    width: 1280px;
  }
</style>
